package controler;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.NhacungcapModel;
import dao.common;
import entity.Nhacungcap;

/**
 * Servlet implementation class adminncc
 */
@WebServlet("/adminncc")
public class adminncc extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public adminncc() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession();
    	common cm = new common();   	
    	try {
			if(cm.checkquyen(session)== false){
				response.sendRedirect("listDanhmuc");
			}
			else{
				List<Nhacungcap> list = new ArrayList<Nhacungcap>();
				NhacungcapModel model = new NhacungcapModel();
				list = model.getlistncc("select * from nhacungcap");
				request.setAttribute("list", list);
				RequestDispatcher view = request.getRequestDispatcher("adminncc.jsp");
			    view.forward(request, response);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
